{% extends "base.html" %}

{% block head %}
  <link rel="stylesheet" href="/static/admin.css" type="text/css"/>
{% endblock %}

{% block body %}
  <form action="{{ web.ctx.path }}" method="post" class="compose">
    <div style="margin-bottom:5px"><input name="title" type="text" class="title" value="{{ entry.title |e if entry else "" }}"/></div>
    <div style="margin-bottom:5px"><textarea name="markdown" rows="30" cols="40" class="markdown">{{ entry.markdown |e if entry else "" }}</textarea></div>
    <div style="margin-bottom:5px"><input name="tag_str" type="text" class="tags" value="{{ entry.tag_str |e if entry else "" }}"/></div>
    <div>
      <div style="float:right"><a href="http://daringfireball.net/projects/markdown/syntax">Syntax documentation</a></div>
      <input type="submit" value="{{ "Save changes" if entry else "Publish post" }}" class="submit"/>
      &nbsp;<a href="{{ "/entry/" + entry.slug if entry else "/" }}">Cancel</a>
    </div>
    {% if entry %}
      <input type="hidden" name="key" value="{{ entry.slug }}"/>
    {% endif %}
  </form>
      <script type="text/javascript">
	      //<![CDATA[
		// to set WMD's options programatically, define a "wmd_options" object with whatever settings
		// you want to override.  Here are the defaults:
        wmd_options = {
			// format sent to the server.  Use "Markdown" to return the markdown source.
			output: "Markdown",

			// line wrapping length for lists, blockquotes, etc.
			lineLength: 40,

			// toolbar buttons.  Undo and redo get appended automatically.
			buttons: "bold italic | link blockquote code image | ol ul heading hr",

			// option to automatically add WMD to the first textarea found.  See apiExample.html for usage.
			autostart: true
	};
//]]>
	</script>
    <script type="text/javascript" src="/static/wmd/wmd.js""></script>
{% endblock %}

{% block bottom %}
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
  <script type="text/javascript">
  //<![CDATA[

    $(function() {
      $("input[name=title]").select();
      $("form.compose").submit(function() {
          var required = ["title", "markdown"];
          var form = $(this).get(0);
          for (var i = 0; i < required.length; i++) {
              if (!form[required[i]].value) {
                  $(form[required[i]]).select();
                  return false;
              }
          }
          return true;
      });
    });

  //]]>
  </script>
{% endblock %}

